import { App, Plugin } from 'vue';

const plugins: Plugin = {
  install: (app) => {
    const modules = import.meta.glob('./**/*.ts');
    Object.values(modules).forEach((item) => {
      item().then((res) => {
        // 类型转换，将unknown 转成 IDirectiveModule
        const { name, directive } = (res as IDirectiveModule).default;
        app.directive(name, directive);
      });
    });
  },
};
export default plugins;

export function setupDirectives(app: App<Element>) {
  app.use(plugins);
}
